#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
int main()
{
	int n = 0, maxx = 0, minn = 100;
	int arr[10] = { 0 };
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
	{
		scanf("%d", &arr[i]); 
		if (arr[i] > maxx) maxx = arr[i];
		if (arr[i] < minn) minn = arr[i];
	}

	for (int j = n - 1; j > 0; j--)
	{
		if (arr[j] == minn) 
		{
			arr[j] = arr[0];
			arr[0] = minn;
		}
	}


	for (int b = 1; b < n - 1; b++)
	{
		if (arr[b] == maxx)
		{
			arr[b] = arr[n - 1];
			arr[n - 1] = maxx;
		}
	}


	for (int a = 0; a < n; a++)
	{
		printf("%d ", arr[a]);
	}
}